package org.javaweb.cms_web.controller;

import org.javaweb.cms_web.model.User;
import org.javaweb.cms_web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;

// 根据邮箱查询用户状态。
@Controller
public class StatusController {

    @Autowired
    private UserService userService;

    @PostMapping("/checkStatus")
    public String checkStatus(@RequestParam("email") String email, Model model) {

        User user = userService.findUserByEmail(email);

        if (user == null) {
            model.addAttribute("message", "未找到该邮箱的注册信息！");
        } else {
            int status = user.getStatus();
            String statusMessage;
            switch (status) {
                case 0:
                    statusMessage = "审核中";
                    break;
                case 1:
                    statusMessage = "审核通过";
                    break;
                case 2:
                    statusMessage = "审核未通过";
                    break;
                case 3:
                    statusMessage = "申请已失效";
                    break;
                default:
                    statusMessage = "未知状态";
                    break;
            }
            model.addAttribute("message", "您的审核状态为：" + statusMessage);
        }

        return "statusResult"; // 跳转到结果页面
    }
}

